<template>
	<view class="wrap bgw">
		<view class="search_Tops p30">
			<u-search :show-action="true" action-text="搜索" :animation="true" :clearabled="true" placeholder="搜索您要找的集市" @search="searchs"  @custom="searchs"  v-model="keyword"></u-search>
		</view>
		<view class="lists_main pt100">
			<view @tap="successs(v)" v-for="(v,i) in data" :key="i" class="list one">
				# {{v.name}} #
			</view>
		</view>
	</view>
</template>

<script>
	import {indexMarkets} from '../../api/api.js'
	export default {
		data() {
			return {
				keyword:'',
				pageNumber:1,
				pageSize:20,
				stops:0,
				data:[]
			};
		},
		created() { 
			this.init() 
		},
		onReachBottom() {
			if(this.stops == 0){
				this.init() 
			}
		},
		methods:{
			searchs(){
				this.data = []
				this.pageNumber = 1
				this.stops = 0
				this.init()
			},
			successs(v){
				let ids = uni.getStorageSync('marketIdsStorage')
				if(ids.indexOf(v.id) == -1){
					uni.setStorageSync('SuccessMarket',v)
					uni.navigateBack()
				}else{
					this.$u.toast(`已选择该集市`);
				} 
			},
			async init(){
				let parameter =  {
					longitude: this.$store.state.longitude,
					latitude: this.$store.state.latitude,
					keyword:this.keyword,
					isIndex:false,
					pageable: {
						pageNumber: this.pageNumber,
						pageSize: this.pageSize
					}
				}
				let datas = await indexMarkets(parameter)
				datas = datas.data
				if (datas.length != this.pageSize) {
					this.stops = 1
				} 
				this.data = [...this.data,...datas]
				this.pageNumber = this.pageNumber + 1
			}
		}
	}
</script>

<style lang="less" scoped>
@import './index.less';
</style>
